﻿/*-----------------------------------------------
// File: BattleMsgCtrl.cs 
// Description: 战场消息管理器，用于管理渲染层与逻辑层的通信
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Battle.Communication;
using ProtoBuf.Message;

namespace Battle
{
    /// <summary>
    /// 战场消息管理器
    /// </summary>
    public class BattleMsgCtrl  
    {
        static BattleMsgCtrl ctrl = null;
        public static BattleMsgCtrl GetInstance() {
            if (ctrl == null) {
                ctrl = new BattleMsgCtrl();
            }
            return ctrl;
        }
        private BattleMsgCtrl() {
            msgCtrl = new MsgCtrl();
            engineMsgReceive = new EngineMsgReceive();
            engineCallBack = new EngineMsgCallback();
            Reset();
        }

        public List<BattleInstruct> instructCache = new List<BattleInstruct>();

        public MsgCtrl msgCtrl {
            get;
            protected set;
        }
        EngineMsgReceive engineMsgReceive;
        public EngineMsgCallback engineCallBack;

        public void Update() {
            if (msgCtrl != null)
            {
                msgCtrl.Update();
            }
        }

        public void Reset()
        {
            msgCtrl.Reset();
            msgCtrl.RegistEngineToViewHandler(PushMessageToView);
            msgCtrl.RegistViewToEngineHandler(engineMsgReceive.PushMessageToEngine);
        }

        void PushMessageToView(BattlePacket bp) {
            BattleManager.Instance.battleViewCtrl.ReceiveMessage(bp);
        }
    }

    public class BattlePacket {
        public int opcode;
        public object kBody;
    }
    

}